layui.define(['Mock', 'apiRole', 'qs'], function (exports) {
	var Mock = layui.Mock,
		api = layui.apiRole.api,
		qs = layui.qs;

	var roleMeta = {
		id: '@integer(2, 5)',
		'name|+1': [
			'管理员',
			'普通成员',
			'测试成员',
		],
		remark: '@cword(10,30)'
	};

	function roleMock() {
		Mock.setup({
			timeout: '50-100'
		})

		/**
		 * @author: ares
		 * @date: 2021/4/27 20:49
		 * @description: 新增
		 */
		Mock.mock(RegExp(api.create + '[^\.]*$'), 'post', function (options) {
			var params = qs.parse(options.url.split('?')[1]),
				body = JSON.parse(options.body);
			return {
				code: 2000,
				msg: '新增角色成功',
			};
		})

		/**
		 * @author: ares
		 * @date: 2021/4/27 20:53
		 * @description: 删除
		 */
		Mock.mock(RegExp(api.remove + '[^\.]*$'), 'delete', function (options) {
			var params = qs.parse(options.url.split('?')[1]),
				body = JSON.parse(options.body);
			return {
				code: 2000,
				msg: '删除角色成功',
			};
		})

		/**
		 * @author: ares
		 * @date: 2021/4/27 20:54
		 * @description: 更新
		 */
		Mock.mock(RegExp(api.update + '[^\.]*$'), 'update', function (options) {
			var params = qs.parse(options.url.split('?')[1]),
				body = JSON.parse(options.body);
			return {
				code: 2000,
				msg: '更新角色成功',
			};
		})

		/**
		 * @author: ares
		 * @date: 2021/4/27 21:06
		 * @description: 列表
		 */
		Mock.mock(RegExp(api.list + '[^\.]*$'), function (options) {
			return Mock.mock({
				code: 2000,
				msg: '获取列表成功',
				data: [
					{id: 2, name: '管理员', remark: '@cword(10,30)'},
					{id: 3, name: '普通成员', remark: '@cword(10,30)'},
					{id: 4, name: '测试成员', remark: '@cword(10,30)'},
				]
			});
		})

		/**
		 * @author: ares
		 * @date: 2021/4/27 21:06
		 * @description: 分页查询
		 */
		Mock.mock(RegExp(api.getPageList + '[^\.]*$'), function (options) {
			var params = qs.parse(options.url.split('?')[1]),
				total = 'total|' + params.pageSize + '-1000',
				list = 'list|' + params.pageSize,
				data = Mock.mock({
					[total]: 0,
					currentPage: params.currentPage,
					[list]: [roleMeta]
				});
			debugger
			return {
				code: 2000,
				msg: '获取列表成功',
				data: data
			}
		})

		/**
		 * @author: ares
		 * @date: 2021/4/27 21:06
		 * @description: 增强型分页查询
		 */
		Mock.mock(RegExp(api.postPageList + '[^\.]*$'), 'post', function (options) {
			var params = qs.parse(options.url.split('?')[1]),
				body = JSON.parse(options.body),
				param = body.param,
				total = 'total|' + params.pageSize + '-1000',
				list = 'list|' + params.pageSize,
				data = Mock.mock({
					[total]: 0,
					currentPage: params.currentPage,
					[list]: [roleMeta]
				});
			return {
				code: 2000,
				msg: '获取列表成功',
				data: data
			}
		})

		/**
		 * @author: ares
		 * @date: 2021/4/27 21:07
		 * @description: 获取详情
		 */
		Mock.mock(RegExp(api.detail + '[^\.]*$'), function (options) {
			var params = qs.parse(options.url.split('?')[1]),
				data = JSON.parse(options.body),
				id = params.id;
			return Mock.mock({
				code: 2000,
				msg: '查询成功',
				data: roleMeta
			})
		})


		/**
		 * @author: ares
		 * @date: 2021/4/28 11:27
		 * @description: 启用禁用角色
		 */
		Mock.mock(RegExp(api.disable + '[^\.]*$'), 'put', function (options) {
			var params = qs.parse(options.url.split('?')[1]),
				body = JSON.parse(options.body);
			return {
				code: 2000,
				msg: '操作成功',
			}
		})

	}

	exports("roleMock", roleMock);
})